package zhuhai
{
	import flash.filesystem.File;
	import flash.display.Stage;
	import flash.display.Sprite;
	import flash.events.Event;
	public class VideoPlay extends Sprite
	{
		private static var header:Header;
		public function VideoPlay()
		{
			_main = this;
			header = new Header("Video");
			//addChild(header).visible = false;

			addEventListener(Event.ADDED_TO_STAGE,init);
		}

		private function init(e:Event):void
		{//黑色背景
			with(graphics)
			{
				clear();
				beginFill(0x0);
				drawRect(0,0,Main.stageWidth,Main.stageHeight);
				endFill();

			}
		}

		private function quit(e:Event):void
		{//退出移除视频
			MyKey.main.removeEventListener(MyKey.CLICK,quit);
			if(!main.visible)
				return;
			main.visible = false;
			Main.show();
			if(video)
			{
				removeChild(video);
				video.removeEventListener(Event.COMPLETE,quit);
				video.stop();
				video = null;
			}
		}
		private static var _main:VideoPlay;
		private static  function get main():VideoPlay
		{
			if(_main==null)
				_main = new VideoPlay;
			return _main;
		}
		private static var video:VideoPlayer;
		public static function show(file:File):void
		{
			//添加此容器到舞台
			var _stage:Stage = Main.main.stage;
			_stage.addChild(main);
			main.visible = true;
			logs.adds("VideoPlay show");

			//播放视频
			video = new VideoPlayer(file.url);
			video.setSize(0,header.height,Main.stageWidth,Main.stageHeight-header.height);
			main.addChild(video);

			//视频退出事件
			video.addEventListener(Event.COMPLETE,main.quit);
			MyKey.main.addEventListener(MyKey.CLICK, main.quit);

			//切换标题
			main.addChild(header);
			header.setTitle(String(file.name));
		}
	}
}
